local skel = fk.CreateSkill {
  name = "rmt__jiawen",
}

skel:addEffect(fk.EventPhaseStart, {
  anim_type = "control",
  times = function (self, player)
    return 1 - player:usedSkillTimes(skel.name, Player.HistoryRound)
  end,
  can_trigger = function (self, event, target, player, data)
    return target ~= player and target.phase == Player.Play and player:hasSkill(skel.name) and not target:isKongcheng()
    and player:usedSkillTimes(skel.name, Player.HistoryRound) == 0
  end,
  on_cost = function (self, event, target, player, data)
    if player.room:askToSkillInvoke(player, {skill_name = skel.name, prompt = "#rmt__jiawen-invoke:"..target.id}) then
      event:setCostData(self, {tos = {target}})
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local cards = target:getCardIds("h")
    target:showCards(cards)
    cards = table.filter(cards, function(id) return Fk:getCardById(id).is_damage_card end)
    if #cards > 0 then
      player.room:delay(600)
      player.room:recastCard(cards, target, skel.name)
    end
  end,
})

skel:addEffect(fk.Damaged, {
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill(skel.name) and player:usedSkillTimes(skel.name, Player.HistoryRound) > 0
  end,
  on_refresh = function(self, event, target, player, data)
    player:setSkillUseHistory(skel.name, 0, Player.HistoryRound)
  end,
})

Fk:loadTranslationTable{
  ["rmt__jiawen"] = "家问",
  [":rmt__jiawen"] = "每轮限一次，其他角色的出牌阶段开始时，你可以展示其所有手牌并重铸其中的伤害类牌。你受到伤害后，重置此技能。",
  ["#rmt__jiawen-invoke"] = "家问：你可以展示 %src 所有手牌，重铸其中的伤害类牌！",

  ["$rmt__jiawen"] = "Free to choose their own leaders, free to select their own system, free to own their own land,"..
  "free to speak and write and worship, without fear.",
}

return skel
